package com.demo.book;

import com.demo.common.model.Book;
import com.demo.common.model.Student;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class BookValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        validateRequiredString("book.bookid", "bookidMsg", "请输入图书索书号!");
        validateRequiredString("book.bookcopyid", "bookcopyidMsg", "请输入图书副本编号!");
        validateRequiredString("book.bookname", "booknameMsg", "请输入图书名称!");
        validateRequiredString("book.bookauthor", "bookauthorMsg", "请输入图书作者!");
        validateRequiredString("book.bookshelfid", "bookshelfidMsg", "请选择所属于书架!");
    }

    @Override
    protected void handleError(Controller controller) {
        controller.keepModel(Book.class);

        String actionKey = getActionKey();
        if (actionKey.equals("/book/save"))
            controller.render("add.html");
        else if (actionKey.equals("/book/update"))
            controller.render("edit.html");
    }
}
